﻿using BLL.AntiFake;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;

namespace NbSecurityAppManage.Ashx
{
    /// <summary>
    /// Handler1 的摘要说明
    /// </summary>
    public class Handler1 : IHttpHandler
    {
       
        public void ProcessRequest(HttpContext context)
        {
            string oper = context.Request.QueryString["oper"];
             string strResult = string.Empty;
            switch(oper){
                case "getlog":
                    strResult = getlog(context);
                    break;
            }
            context.Response.ContentType = "text/plain";
            context.Response.Write(strResult);
        }
        public string getlog(HttpContext context)
        {
            DigitCodeBLL digitCodeBLL = new DigitCodeBLL();
            var code = context.Request.QueryString["code"];
            DataTable dt = digitCodeBLL.getQueryLog(code);
            string strJson = DataTable2Json(dt);
            return strJson;


        }
        public static string DataTable2Json(DataTable dt)
        {
            StringBuilder jsonBuilder = new StringBuilder();
           
            jsonBuilder.Append("[");
           
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                jsonBuilder.Append("{");
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    jsonBuilder.Append("\"");
                    jsonBuilder.Append(dt.Columns[j].ColumnName);
                    jsonBuilder.Append("\":\"");
                    jsonBuilder.Append(dt.Rows[i][j].ToString());
                    jsonBuilder.Append("\",");
                }
                jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
                jsonBuilder.Append("},");
            }
            jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
            jsonBuilder.Append("]");
          
            return jsonBuilder.ToString();
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}